/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author Cinthia
 */
public class Conexao<T>{

    protected Connection conexao;


    private String url = "jdbc:postgresql://localhost:5432/prova";
    private String user = "postgres";
    private String password = "postgres";
    private String postgresqlDriver = "org.postgresql.Driver";
    private Connection connection;

        public Connection conectar() throws Exception {
            return criaConexao(false);
    }
        
    
    protected Connection criaConexao(Boolean autocommit) throws Exception {
        try {
            Class.forName(postgresqlDriver);
        } catch (ClassNotFoundException e) {
            throw e;
        }
        try {
            connection = DriverManager.getConnection(url, user, password);
            connection.setAutoCommit(autocommit);
        } catch (SQLException e) {
            throw e;
        }
        return connection;
    }

    protected void fechaConexao() throws SQLException {
        try {
            connection.close();
        } catch (SQLException e) {
            throw e;
        }
    }
}
